package com.example.cloud.common;

import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {
    private List<T> records;
    private Long total;
    private Long pageSize;
    private Long pageNum;
    private Long totalPages;
    
    // 游标分页参数
    private Long lastId;  // 当前页最后一条记录ID
    private String lastValue;  // 当前页最后一条记录的值
    private boolean hasMore;  // 是否还有更多数据
    
    public static <T> PageResult<T> of(List<T> records, Long total, Long pageSize, Long pageNum) {
        PageResult<T> result = new PageResult<>();
        result.setRecords(records);
        result.setTotal(total);
        result.setPageSize(pageSize);
        result.setPageNum(pageNum);
        result.setTotalPages((total + pageSize - 1) / pageSize);
        return result;
    }
    
    public static <T> PageResult<T> of(List<T> records, Long lastId, String lastValue, boolean hasMore) {
        PageResult<T> result = new PageResult<>();
        result.setRecords(records);
        result.setLastId(lastId);
        result.setLastValue(lastValue);
        result.setHasMore(hasMore);
        return result;
    }
} 